﻿#include "stdafx.h"
#include "RoutineConfig.h"
#include "DB/DbTool.h"
#include "DefInfo/GameInfo.h"
#include "boost/format.hpp"

double GeneralConfig::MinHealSpellTrigger_HpPecent()
{
	return heal_min_lower * 1.0f / 1000.0f;
}

void InterfaceClassConfig::UpdateProperty(Property& prop)
{
	for (auto& prop_com : vec_property)
	{
		if (prop_com.name == prop.name)
		{
			prop_com = prop;
			prop_com.Print();
		}
	}
}

bool InterfaceClassConfig::CheckCache()
{
	if (!has_cache)
	{
		map_cache_property.clear();
		for (auto& prop : vec_property)
		{
			map_cache_property[prop.name] = &prop;
		}
		has_cache = true;
	}
	return has_cache;
}

RoutineConfig::RoutineConfig()
{
	IClassConfigPtr ptr_dres_config = std::make_shared<InterfaceClassConfig>();
	ClassConfig[Restoration] = ptr_dres_config;
	ptr_dres_config->vec_property = {
	{"回春术",(double)0.1f,11413, PC_if_hp_percent_less_then_value, Restoration},
	{"无buff 愈合",(double)0.2f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"生命绽放",(double)0.3f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"塞纳里奥结界",(double)0.35f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"野性生长",(double)0.1f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"有buff 愈合",(double)0.4f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"迅捷治愈",(double)0.4f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"铁木树皮-坦克",(double)0.3f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"铁木树皮-自己",(double)0.45f, 1,PC_if_hp_percent_less_then_value, Restoration},
	{"最低血量愈合",(double)0.4f, 1,PC_if_hp_percent_less_then_value, Restoration},
	};
	ptr_dres_config = std::make_shared<InterfaceClassConfig>();
	ClassConfig[Balance] = ptr_dres_config;
}

void RoutineConfig::UpdateByDB()
{
	auto& vec_prop = DbTool::inst().GetPropertyConfig();
	for (auto& prop_it : vec_prop)
	{
		GameInfo::inst().GetRoutineConfig().ClassConfig[prop_it->spec_id]->UpdateProperty(*prop_it);
	}
}

Property& Property::operator=(const Property& prop)
{
	Property& prop_com = *this;
	prop_com.value = prop.value;
	prop_com.value2 = prop.value2;
	prop_com.condition = prop.condition;
	prop_com.spec_id = prop.spec_id;
	return prop_com;
}

void Property::SaveConfig()
{
}

void Property::Print()
{
	CString strMsg;
	CA2W name(name.c_str());
	std::string msg = str(boost::format("value type: %s, value2 type:%d") % value.type().name() % value2.type().name());

	strMsg.Format(L"prop name:%s, value:%.3f, value2:%d condition:%d \n", name.m_psz, std::any_cast<double>(value), std::any_cast<int>(value2), condition);
	OutputDebugString(strMsg);
}
